package com.houdoudou.bean;

import javax.servlet.http.HttpServletRequest;

public class Box {

	
	int id=-1;
	int machine=-1;
	int state=-1; //1 表正常，，4表示故障锁定。
	//long orderID=-1;
	String owner="";
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getMachine() {
		return machine;
	}
	public void setMachine(int machine) {
		this.machine = machine;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	
	
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public static Box beanFromRequest(HttpServletRequest req) throws Exception{
		Box box= new Box();
		if(req.getParameter("owner")!=null){
			if(!req.getParameter("owner").isEmpty()){
				box.setOwner(req.getParameter("owner"));
			}
		}
		if(req.getParameter("machine")!=null){
			if(!req.getParameter("machine").isEmpty()){
				int machine= Integer.parseInt(req.getParameter("machine"));
				box.setMachine(machine);
			}
		}
		if(req.getParameter("id")!=null){
			if(!req.getParameter("id").isEmpty()){
				int id= Integer.parseInt(req.getParameter("id"));
				box.setId(id);
			}
		}
		if(req.getParameter("state")!=null){
			if(!req.getParameter("state").isEmpty()){
				int state= Integer.parseInt(req.getParameter("state"));
				box.setState(state);
			}
		}
		
		print("bean from request ",box);
		return  box;
	}
	
	public static void  print(String when, Box box){
		System.out.println(when+" boxBean " 
				+" owner="+ box.getOwner()
				+" machine=" +box.getMachine()
				+" id=" +box.getId()
				+" state=" +box.getState()
				
				);
	}
}
